#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: filter csvs of scores and organisms for interesting features
#Usage: ./filter.pl [config file | options] <filterable csv>

my $config = shift;
if (! -e $config) {
	print STDERR "Not worrying about this now... someday I will punish you.\n";
}

#Currently, we are just assuming that we require at least 4 distinct organisms for a file to be interesting.
my $min_orgs = 4;

while (my $line = <>) {
	chomp $line;
	my @splitline = split(/\s+/, $line);
	my %orgs;
	foreach $thing (@splitline) {
		if ($thing =~ /\|/) {
			my $org = [split(/\|/,$thing)]->[0];
			$orgs{$org}++;
		}
	}
	if(scalar(keys(%orgs)) > $min_orgs) {
		print $line . "\n";
	}
}
